package gcontent.config.node;

import gcontent.config.error.ConfigEx;

import java.util.HashMap;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/* simple node of one level */
public class SimpleNode {
	
	protected HashMap<String, String> node_list = new HashMap<String, String>();
	protected String id = "";
	
	public String getId()
	{
		return this.id;
	}
	
	public HashMap<String, String> getNodes()
	{
		return this.node_list;
	}
	
	public SimpleNode(Node root) throws ConfigEx
	{
		NodeList nodes;
		NamedNodeMap node_map; 
		
		node_map = root.getAttributes();
		if(node_map == null || node_map.getNamedItem("id") == null)
			throw new ConfigEx("not attribute id found it on node " + root.getNodeName());
		
		this.id = node_map.getNamedItem("id").getTextContent();
				
		nodes = root.getChildNodes();
		for(int i = 0; nodes.item(i) != null; i++) {
			Node node;
			
			node = nodes.item(i);
			this.node_list.put(node.getNodeName(), node.getTextContent());
		}
	}

}
